package com.nescafe.nescafepromo;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.FacebookApi;
import org.scribe.oauth.OAuthService;


public class NPServletContextListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO free resources

	}

	@Override
	public void contextInitialized(ServletContextEvent sce) {

		ServletContext context = sce.getServletContext();

		for (NPContextParameters param : NPContextParameters.values()) {
			param.setValue(context.getInitParameter(param.toString()));
		}
				
		NescafePromo np = NescafePromo.get();
		
		OAuthService service = new ServiceBuilder()
        .provider(FacebookApi.class)
        .apiKey(NPContextParameters.FB_APP_ID.getValue())
        .apiSecret(NPContextParameters.FB_APP_SECRET.getValue())
        .callback("http://apps.facebook.com/nescafepromo")
        //.callback("http://localhost:8888/")
        .build();
		//
		np.setFBAuthService(service);
				
		

	}

}
